<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择人才')" />
    <style type="text/css">
    	.layui-form-label{width:70px}
    	.layui-input-block{margin-left: 80px;}
    </style>
</head>
<body>
<div style="padding: 0 10px;">
	<div class="layui-inline layui-col-md9">
		<div class="layui-inline layui-col-md12"><table class="layui-hide" id="dhtable" lay-filter="ftable"></table></div>
		<div class="layui-inline layui-col-md12"><table class="layui-hide" id="dhtable2" lay-filter="ftable2"></table></div>
	</div>
	<div class="layui-inline layui-col-md3">
		<form> 
		    <div class="layui-form layui-form-item">
	            <label class="layui-form-label">所属公司：</label>
	            <div class="layui-input-block">
                   	<input type="text" id="cidName" name="cidName" autocomplete="off" class="layui-input" style="display:inline-block">
                   		<i class="layui-icon layui-icon-more" onclick="getCompany()" style="position: absolute;right: 5px;top: 5px;"></i>
	            </div> 
	            <label class="layui-form-label">岗位：</label>
	            <div class="layui-input-block">
                   	<input type="text" id="position" name="position" autocomplete="off" class="layui-input">
				</div>
	            <label class="layui-form-label">姓名：</label>
	            <div class="layui-input-block">
                   	<input type="text" id="userName" name="userName" autocomplete="off" class="layui-input">
	            </div>
	            <label class="layui-form-label">发布城市：</label>
	            <div class="layui-input-block">
                   	<input type="text" id="vFfCs" name="vFfCs" autocomplete="off" class="layui-input">
				</div>
				<div style="float: right;margin-right: -50px;margin-top: 10px;">
			    	<a class="layui-btn layuiadmin-btn-order dhicon dh-search" id="btn-search"><span class="fa_span">查询</span></a>
		            <button type="reset" class="layui-btn layui-btn-primary dhicon dh-refresh" id="dh-resets"><span class="fa_span">重置</span></button>
	            </div>
			    <div class="layui-btn-container" style="width: 50px;text-align: center;margin-top:100px;float:left;">
		        <div class="layui-btn addbtn layui-btn-disabled" shiro:hasPermission="system:user:add" style="padding:0 10px;margin-right: 0;">
		            <p class="dhicon dh-angle-double-down" style="font-size:14px;margin:0;color:#C9C9C9"></p>
		        </div>
		        <div class="layui-btn delbtn layui-btn-disabled" shiro:hasPermission="system:user:add" style="padding:0 10px;margin-right: 0;">
		            <p class="dhicon dh-angle-double-up" style="font-size:14px;margin:0;color:#C9C9C9"></p>
		        </div>
				</div>
			</div>
		</form>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "hr/talentpool",
		gridColumns=[[${gridColumns}]];
	/*]]>*/
</script>
<script type="text/javascript">
var $,layer,table,form;
layui.use(['table','layer','jquery','form'], function () {
    $ = layui.$,layer = layui.layer,table = layui.table,form = layui.form;
    $.each(gridColumns.gridBody,function(i,v){
    	if(v.type=='checkbox')v.fixed=false;//去除表格复选框固定，固定会生成两个复选框（单据选中样式出错）
    })
    $.tablelist.init({
        elem: '#dhtable'
        ,url: prefix+"/list"
        ,cols: [gridColumns.gridBody
        ]
        ,height:300
        ,width:750
    });
	//点击table行选中复选框
	$(document).on("click",".layui-table-body table.layui-table tbody tr",function(){
       var obj = event ? event.target : event.srcElement;
       var tag = obj.tagName;
       var checkbox = $(this).find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
       if(checkbox.length!=0){
           if(tag == 'DIV') {
               checkbox.click();
           }
       }
	});
	//点击复选框阻止冒泡
	$(document).on("click",".layui-form-checkbox",function(e){
      	e.stopPropagation();
       var checkStatus = table.checkStatus('dhtable');
       var checkStatus2 = table.checkStatus('dhtable2');
       var data = checkStatus.data, data2 = checkStatus2.data;
       if(data.length > 0){
       	$(".addbtn").removeClass("layui-btn-disabled");
       	$(".addbtn").children().css('color','#fff');
      	}else{
      		$(".addbtn").addClass("layui-btn-disabled");
      		$(".addbtn").children().css('color','#C9C9C9');
     		}
       if(data2.length > 0){
       	$(".delbtn").removeClass("layui-btn-disabled");
       	$(".delbtn").children().css('color','#fff');
      	}else{
      		$(".delbtn").addClass("layui-btn-disabled");$(".delbtn").children().css('color','#C9C9C9');
   		}
	});
	$('#btn-search').on('click', function () {
		table.reload('dhtable', {
			where:{
				cidName:$("#cidName").val(),
				position:$("#position").val(),
				userName:$("#userName").val(),
				vFfCs:$("#vFfCs").val()
			},
			page:{curr: 1}
		});
	});
});
$('.addbtn').click(function(){
	var checkStatus = table.checkStatus('dhtable'),data = [];
    data = checkStatus.data;
   	$.each(data,function(i,v){
   		var flag = false;
   		for(var j=0; j < dataStr.length; j++){
			if(v.guid == dataStr[j].guid)flag = true;			
		}
   		if(!flag)dataStr.push(v);	//排除已选中
   	});
   	rend();
   	$('div.laytable-cell-checkbox').find('div.layui-form-checked').click();
   	$(".addbtn").addClass("layui-btn-disabled");
   	$(".addbtn").children().css('color','#C9C9C9');
})
$('.delbtn').click(function(){
	var checkStatus = table.checkStatus('dhtable2'),data = [];
	   data = checkStatus.data;
	$.each(data,function(i,v){
		for(var j=0; j < dataStr.length; j++){
			if(v.guid == dataStr[j].guid)dataStr.splice(j,1);
		}
	});
	rend();
	$(".delbtn").addClass("layui-btn-disabled");$(".delbtn").children().css('color','#C9C9C9');
})
var callbackdata = function () {
    return dataStr;
}
var dataStr = [];
$(function(){
	rend();
})
//渲染表格
function rend(){
    $.tablelist.init({
        elem: '#dhtable2'
        ,cols: [gridColumns.gridBody
        ]
    	,data:dataStr
        ,height:300
        ,width:750
    });
}
//选择公司
function getCompany(){
	$.modal.open('选择所属公司','/base/company/select',null,null,function(index){
		var res = window["layui-layer-iframe" + index].callbackdata();
	      if(res=="none" || !res){//没有选中时
	      	layer.msg("请选择！", {icon:7});
	      }else{
	      	$('#cidName').val(res.vName);
	      	layer.close(index);
	      }
	})
}
</script>
</body>
</html>